命令参考

crossplane CLI 提供了一些实用程序,让使用 crossplane 变得更容易。

请阅读 Crossplane CLI overview 页面,了解有关安装 crossplane 的信息。

global flags

以下 flag 适用于所有命令。

| 短标志 | 长标志 | 说明 | |————|————-|——————————| | -h | --help | 显示上下文相关帮助。 | | -v | --version | 打印版本并退出。 | | | --verbose | 打印冗余输出。

xpkg

crossplane xpkg` 命令用于创建、安装和更新 Crossplane packages 以及启用身份验证和将 crossplane 软件包发布到 crossplane 软件包注册表。

xpkg build

被引用的 “crossplane xpkg build “提供了构建 crossplane 软件包的自动化和简化。

crossplane CLI 将 YAML 文件目录组合在一起,并将其打包为 OCI 容器镜像

CLI 应用所需的 Annotations 和 Values,以满足 crossplane XPKG 规范

crossplane “CLI支持构建配置函数Provider 包类型。

flag

Short flag Long flag Description
--embed-runtime-image-name=NAME The image name and tag of an image to include in the package. Only for provider and function packages.
--embed-runtime-image-tarball=PATH The filename of an image to include in the package. Only for provider and function packages.
-e --examples-root="./examples" The path to a directory of examples related to the package.
--ignore=PATH,... List of files and directories to ignore.
-o --package-file=PATH Directory and filename of the created package.
-f --package-root="." Directory to search for YAML files

crossplane xpkg build命令会递归查找由–package-root设置的目录,并尝试将任何以.yml.yaml` 结尾的文件合并为一个软件包。

所有 YAML 文件都必须是有效的 Kubernetes 配置清单,并包含 apiVersionkindmetadataspec 字段。

忽略文件

使用 --ignore 可以提供要忽略的文件和目录列表。

例如,“crossplane xpkg build –ignore=”./test/*,kind-config.yaml”`

设置 package 名称

crossplane 会自动以 metadata.name 和软件包内容哈希值的组合为新软件包命名,并将内容保存在与 --package-root 相同的位置。 使用 --package-file-o 定义特定位置和文件名。

例如,“crossplane xpkg build -o /home/crossplane/example.xpkg`"。

包括实例

包含 YAML 文件,演示如何通过 --examples-root 使用 packages。

upbound市场 使用被引用为”–examples-root “的文件作为已发布软件包的文档。

包括运行时镜像

函数和 Providers 需要描述其依赖关系和设置的 YAML 文件,以及运行时的容器镜像。

使用 --embed-runtime-image-name可运行指定镜像,并将镜像包含在函数或 Providers package 内。

Note

使用 --embed-runtime-image-name 引用的镜像必须在本地 Docker 缓存中。

使用 docker pull 下载丢失的镜像。

embed-runtime-image-tarball “标志将本地 OCI 镜像压缩包包含在函数或 Providers 包内。

xpkg install

使用 crossplane xpkg install 将软件包下载并安装到 crossplane 中。

默认情况下,“crossplane xpkg install “命令被引用在”~/.kube/config “中定义的 Kubernetes 配置。

使用环境变量 “KUBECONFIG “定义自定义 Kubernetes 配置文件位置。

指定软件包类型、软件包文件,还可选择在 crossplane 中为软件包命名。

crossplane xpkg install<package-kind> <registry URL package name and tag> [<optional-name>]

可以是配置、功能或 Provider。

例如,要安装 0.42.0 版的 AWS S3 Provider:

crossplane xpkg install provider xpkg.upbound.io/upbound/provider-aws-s3:v0.42.0

flag

| Short flag | Long flag | Description | | ———— | ————- | —————————— | | | --runtime-config=<runtime config name> | Install the package with a runtime configuration. | | -m | --manual-activation | Set the revisionActiviationPolicy to Manual. | | | --package-pull-secrets=<list of secrets> | A comma-separated list of Kubernetes secrets to use for authenticating to the package registry. | | -r | --revision-history-limit=<number of revisions> | Set the revisionHistoryLimit. Defaults to 1. | | `

等待软件包安装

安装软件包时,“crossplane xpkg install “命令不会等待软件包下载和安装。 使用 “kubectl describe configuration “检查 “配置”,查看是否存在下载或安装问题。

使用 --wait,可以让 crossplane xpkg install 命令等待软件包达到 HEALTHY 条件后再继续。 如果在软件包达到 HEALTHY 条件之前 wait 时间已过,命令将返回错误。

需要手动激活 package

将软件包设置为 require manual activation,防止自动升级带有 --manual-activation 的软件包

对私人注册表进行身份验证

要对私有软件包注册表进行身份验证,请引用 --package-pull-secrets,并提供 Kubernetes Secret 对象列表。

Important
secrets 必须与 crossplane pod 位于同一个 namespace 中。

自定义存储软件包版本的数量

默认情况下,crossplane 只在本地软件包缓存中存储单个非活动软件包。

使用 --revision-history-limit 存储更多软件包的非活动副本。

有关 packages revisions 在 packages 文档中。

xpkg 登录

使用 xpkg loginupbound Marketplace 容器注册表 xpkg.upbound.io 进行身份验证。

在 upbound Marketplace 注册 来推送软件包和创建私有软件仓库。

flag

| 短标志 | 长标志 | 说明 | | ———— | ————- | —————————— | | -u | -用户名=<username>| | 验证时要使用的用户名。 | | -p|-密码=| | 验证时要使用的密码。 | | -t | -令牌=<token string>| | 验证时要使用的用户令牌字符串。 | | -a|-账户=| | 验证时指定一个 upbound 组织。

验证选项

crossplane xpkg login` 命令可以被引用用户名和密码或 upbound API 令牌。

默认情况下,“crossplane xpkg login “不带参数,会提示输入用户名和密码。

使用--username--password标志提供用户名和密码,或设置环境变量UP_USER以获得用户名,或设置UP_PASSWORD以获得密码。

通过 --tokenUP_TOKEN 环境变量,使用 upbound 用户令牌代替用户名和密码。

Important
-token “或 “UP_TOKEN “环境变量优先于用户名和密码。

使用 - 作为 --password--token 的输入,会从 stdin 读取输入。 例如,“crossplane xpkg login –password -`"。

登录后,crossplane CLI 会在 .crossplane/config.json 中创建一个 profile 来缓存非特权账户信息。

Note

config.json文件中的session` 字段是会话 cookie 标识符。

session “值不被引用用于身份验证。 这不是一个 “令牌”。

与注册的 upbound 组织进行身份验证

使用”–账户 “选项,连同用户名和密码或令牌,向 upbound Marketplace 中的注册组织进行身份验证。

例如,crossplane xpkg login --account=Upbound --username=my-user --password -

xpkg 注销

使用 crossplane xpkg logout 使当前的 crossplane xpkg login 会话失效。

Note
被引用 crossplane xpkg logout 会删除 ~/.crossplane/config.json 文件中的 session ,但不会删除配置文件。

xpkg push

将 crossplane 软件包文件推送到软件包注册表。

Crossplane CLI 默认会将镜像推送到位于 xpkg.upbound.ioUpbound Marketplace

Note
推送软件包可能需要使用 crossplane xpkg login 进行身份验证

crossplane xpkg push<package> 指定组织、软件包名称和标签

默认情况下,该命令会在当前目录下查找要推送的单个 .xpkg 文件。

要推送多个文件或指定特定的 .xpkg 文件,请使用 -f flag。

例如,要将名为 “my-package “的本地软件包推送到 “crossplane-docs/my-package:v0.14.0”,请使用

crossplane xpkg push -f my-package.xpkg crossplane-docs/my-package:v0.14.0

要推送到其他软件包注册表,如 DockerHub,请提供完整的 URL 和软件包名称。

例如,要将名为 “my-package “的本地包推送到 DockerHub 组织 “crossplane-docs/my-package:v0.14.0”,请使用: “crossplane xpkg push -f my-package.xpkg index.docker.io/crossplane-docs/my-package:v0.14.0`.

flag

| 短 flag | 长 flag | 说明 | | ———— | ————- | —————————— | | -f | --package-files=PATH | 用逗号分隔的要推送的 xpkg 文件列表。

xpkg更新

crossplane xpkg update “命令下载并更新现有软件包。

默认情况下,“crossplane xpkg update “命令被引用”~/.kube/config “中定义的 Kubernetes 配置。

使用环境变量 “KUBECONFIG “定义自定义 Kubernetes 配置文件位置。

指定软件包种类、软件包文件,还可指定已安装在 crossplane 中的软件包名称。

crossplane xpkg update<package-kind> <registry package name and tag> [<optional-name>]

软件包文件必须是 Upbound Marketplacexpkg.upbound.io 注册表中的组织、镜像和标签。

例如,要更新到版本 0.42.0 的 AWS S3 Provider:

crossplane xpkg 更新 Provider xpkg.upbound.io/upbound/provider-aws-s3:v0.42.0

beta

crossplane beta命令是试验性的。 这些命令可能会在未来的发布版本中改变 flag、选项或输出。

crossplane 维护者可能会在未来发布的版本中推广或删除 beta 下的相应命令。

测试版渲染

crossplane beta render “命令预览composition资源 应用任何 composition函数.

Important

crossplane beta render “命令不应用打补丁和变换.

该命令仅支持 “打补丁和变换 “功能。

crossplane beta render 命令会连接到本地运行的 Docker 引擎,拉取并运行 Composition 功能。

Important
运行 crossplane beta render 需要 Docker

Provider 一个复合资源、Composition 和 Composition 函数 YAML 定义,并附带在本地渲染 Output 的命令。

例如,“crossplane beta render XR.yaml Composition.yaml function.yaml

输出包括原始 Composition 资源和生成的 managed 资源。

 1---
 2apiVersion: nopexample.org/v1
 3kind: XBucket
 4metadata:
 5  name: test-xrender
 6status:
 7  bucketRegion: us-east-2
 8---
 9apiVersion: s3.aws.upbound.io/v1beta1
10kind: Bucket
11metadata:
12  annotations:
13    crossplane.io/composition-resource-name: my-bucket
14  generateName: test-xrender-
15  labels:
16    crossplane.io/composite: test-xrender
17  ownerReferences:
18  - apiVersion: nopexample.org/v1
19    blockOwnerDeletion: true
20    controller: true
21    kind: XBucket
22    name: test-xrender
23    uid: ""
24spec:
25  forProvider:
26    region: us-east-2

flag

| 短标志 | 长标志 | 说明 | | ———— | ————- | —————————— | | | --context-files=<key>=<file>,<key>=<file>| 为函数 "上下文 "加载的以逗号分隔的文件列表。" | | | –context-values==,=| 为函数 “上下文 “加载的以逗号分隔的键值对列表。” | | -r | --include-function-results | 包括函数的 “结果 “或事件。

crossplane beta render` 命令依靠标准的 Docker 环境变量 连接到本地 Docker 引擎并运行 Composition 功能。

提供功能上下文

--context-files--context-values 标志可以为函数的 context 提供数据。 上下文是 JSON 格式的数据。

包括函数结果

如果函数会产生带有状态的 Kubernetes 事件,请使用 --include-function-results,将它们与托管资源输出一起打印出来。

模拟受管资源

--observed-resources提供代表托管资源的模拟或人工数据。 crossplane beta render`命令会将所提供的输入视为 Crossplane 集群中的资源。

函数在运行过程中可以引用和操作包含的资源。

观察到的资源 “可以是包含多个资源的单个 YAML 文件,也可以是代表多个资源的 YAML 文件目录。

在 YAML 文件中包含一个apiVersion,类型,元数据规格.

1apiVersion: example.org/v1alpha1
2kind: ComposedResource
3metadata:
4  name: test-render-b
5  annotations:
6    crossplane.io/composition-resource-name: resource-b
7spec:
8  coolerField: "I'm cooler!"

资源模式未经验证,可能包含任何数据。

###β 痕量

使用 crossplane beta trace 命令可显示 crossplane 对象的可视化关系。 trace 命令支持 claims、composition 或 managed resources。

该命令需要一个资源类型和一个资源名称。

crossplane beta trace<resource kind> <resource name>

例如,要查看类型为 example.crossplane.io 的名为 my-claim 的资源: crossplane beta trace example.crossplane.io my-claim

该命令还接受 Kubernetes CLI 风格的 <kind>/<name> 输入。例如,crossplane beta trace example.crossplane.io/my-claim

默认情况下,“crossplane beta trace “命令被引用在”~/.kube/config “中定义的 Kubernetes 配置。

使用环境变量 “KUBECONFIG “定义自定义 Kubernetes 配置文件位置。

flag

| 短标志 | 长标志 | 说明 | | ———— | ————- | —————————— | | -n | --namespace | 资源的命名空间。 | | -o | --output= | 使用 widejsondot 更改图形输出,以获得 Graphviz dot 输出。 | | -s | --show-connection-secrets | 打印任何连接secret名称。 不打印secret值。

输出选项

默认情况下,“crossplane beta trace “直接打印到终端,将 “就绪 “条件和 “状态 “信息限制为 64 个字符。

下示例输出了 AWS 参考平台的 “集群 “claim,其中包括多个 Composition 和composition资源:

 1crossplane beta trace cluster.aws.platformref.upbound.io platform-ref-aws
 2NAME SYNCED READY STATUS
 3Cluster/platform-ref-aws (default)                                True True Available
 4└─ XCluster/platform-ref-aws-mlnwb True True Available
 5   ├─ XNetwork/platform-ref-aws-mlnwb-6nvkx True True Available
 6   │  ├─ VPC/platform-ref-aws-mlnwb-ckblr True True Available
 7   │  ├─ InternetGateway/platform-ref-aws-mlnwb-r7w47 True True Available
 8   │  ├─ Subnet/platform-ref-aws-mlnwb-lhr4h True True Available
 9   │  ├─ Subnet/platform-ref-aws-mlnwb-bss4b True True Available
10   │  ├─ Subnet/platform-ref-aws-mlnwb-fzbxx True True Available
11   │  ├─ Subnet/platform-ref-aws-mlnwb-vxbf4 True True Available
12   │  ├─ RouteTable/platform-ref-aws-mlnwb-cs9nl True True Available
13   │  ├─ Route/platform-ref-aws-mlnwb-vpxdg True True Available
14   │  ├─ MainRouteTableAssociation/platform-ref-aws-mlnwb-sngx5 True True Available
15   │  ├─ RouteTableAssociation/platform-ref-aws-mlnwb-hprsp True True Available
16   │  ├─ RouteTableAssociation/platform-ref-aws-mlnwb-shb8f True True Available
17   │  ├─ RouteTableAssociation/platform-ref-aws-mlnwb-hvb2h True True Available
18   │  ├─ RouteTableAssociation/platform-ref-aws-mlnwb-m58vl True True Available
19   │  ├─ SecurityGroup/platform-ref-aws-mlnwb-xxbl2 True True Available
20   │  ├─ SecurityGroupRule/platform-ref-aws-mlnwb-7qt56 True True Available
21   │  └─ SecurityGroupRule/platform-ref-aws-mlnwb-szgxp True True Available
22   ├─ XEKS/platform-ref-aws-mlnwb-fqjzz True True Available
23   │  ├─ Role/platform-ref-aws-mlnwb-gmpqv True True Available
24   │  ├─ RolePolicyAttachment/platform-ref-aws-mlnwb-t6rct True True Available
25   │  ├─ Cluster/platform-ref-aws-mlnwb-crrt8 True True Available
26   │  ├─ ClusterAuth/platform-ref-aws-mlnwb-dgn6f True True Available
27   │  ├─ Role/platform-ref-aws-mlnwb-tdnx4 True True Available
28   │  ├─ RolePolicyAttachment/platform-ref-aws-mlnwb-qzljh True True Available
29   │  ├─ RolePolicyAttachment/platform-ref-aws-mlnwb-l64q2 True True Available
30   │  ├─ RolePolicyAttachment/platform-ref-aws-mlnwb-xn2px True True Available
31   │  ├─ NodeGroup/platform-ref-aws-mlnwb-4sfss True True Available
32   │  ├─ OpenIDConnectProvider/platform-ref-aws-mlnwb-h26xx True True Available
33   │  └─ ProviderConfig/platform-ref-aws                          -        -
34   └─ XServices/platform-ref-aws-mlnwb-bgndx True True Available
35      ├─ Release/platform-ref-aws-mlnwb-bcj7r True True Available
36      └─ Release/platform-ref-aws-mlnwb-7hfkv True True Available

宽幅输出

如果 “就绪 “或 “状态 “信息长度超过 64 个字符,则使用 --output=wide打印整个信息。

例如,Output 会截断过长的 “状态 “信息。

1crossplane trace cluster.aws.platformref.upbound.io platform-ref-aws
2NAME SYNCED READY STATUS
3Cluster/platform-ref-aws (default)                                True False Waiting: ...resource claim is waiting for composite resource to become Ready

被引用 --output=wide 可查看完整信息。

1crossplane trace cluster.aws.platformref.upbound.io platform-ref-aws --output=wide
2NAME SYNCED READY STATUS
3Cluster/platform-ref-aws (default)                                True False Waiting: Composite resource claim is waiting for composite resource to become Ready

Graphviz dot 文件输出

使用 --output=dot 可以打印出文本 Graphviz dot输出。

保存输出并将其导出,或将输出直接导入 Graphviz dot 以渲染镜像。

例如,要将输出保存为 graph.png 文件,请使用 dot -Tpng -o graph.png

crossplane beta trace集群.aws.platformref.upbound.io platform-ref-aws -o dot | dot -Tpng -o graph.png

打印连接secret

使用 -s 可将任何连接 secret 名称与其他资源一起打印出来。

Important
crossplane beta trace` 命令不打印 secret 值。

输出结果包括secret名称和secret的 namespace。

 1NAME SYNCED READY STATUS
 2Cluster/platform-ref-aws (default)                                          True True Available
 3└─ XCluster/platform-ref-aws-mlnwb True True Available
 4   ├─ XNetwork/platform-ref-aws-mlnwb-6nvkx True True Available
 5   │  ├─ SecurityGroupRule/platform-ref-aws-mlnwb-szgxp True True Available
 6   │  └─ Secret/3f11c30b-dd94-4f5b-aff7-10fe4318ab1f (upbound-system)       -        -
 7   ├─ XEKS/platform-ref-aws-mlnwb-fqjzz True True Available
 8   │  ├─ OpenIDConnectProvider/platform-ref-aws-mlnwb-h26xx True True Available
 9   │  └─ Secret/9666eccd-929c-4452-8658-c8c881aee137-eks (upbound-system)   -        -
10   ├─ XServices/platform-ref-aws-mlnwb-bgndx True True Available
11   │  ├─ Release/platform-ref-aws-mlnwb-7hfkv True True Available
12   │  └─ Secret/d0955929-892d-40c3-b0e0-a8cabda55895 (upbound-system)       -        -
13   └─ Secret/9666eccd-929c-4452-8658-c8c881aee137 (upbound-system)          -        -

beta xpkg init

crossplane beta xpkg init 命令会在当前目录下填充文件,以构建软件包。

Provider 被引用的软件包名称和软件包模板应从命令 crossplane beta xpkg init<name> <template>开始。

输入没有被引用。Crossplane 为将来的发布保留了`。